<template>
  <div class="equityInfo-Container">
    <div class="head">
      <div class="opt">
        <router-link to="/equity">
          <el-button size="small" type="primary">返回</el-button>
        </router-link>
      </div>
      <div class="search">
        <el-input placeholder="请输入项目名称,项目代币" suffix-icon="el-icon-search" v-model="search"   @keyup.enter.native="getList()"></el-input>
      </div>
    </div>

    <el-table :data="List" border style="width: 100%">
      <!-- <el-table-column type="selection" width="55"></el-table-column> -->
      <el-table-column prop="index" label="序号" width="120"></el-table-column>
      <el-table-column prop="userNikeName" label="权益人姓名"></el-table-column>
      <el-table-column prop="userPhone" label="手机号"></el-table-column>
      <el-table-column label="用户类型">
        <template slot-scope="scope">
          <el-button type="text" v-show="scope.row.userType  == 1">个人</el-button>
          <el-button type="text" v-show="scope.row.userType  == 2">机构</el-button>
          <el-button type="text" v-show="scope.row.userType  == 3">项目方</el-button>
          <el-button type="text" v-show="scope.row.userType  == 4">平台方</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="userSum" label="持有数量"></el-table-column>
      <el-table-column prop="ratio" label="权益比例(%)"></el-table-column>
      <el-table-column prop="money" label="待分配分红(MOV)"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="text" v-show="scope.row.type == 0">未发放</el-button>
          <el-button type="text" v-show="scope.row.type == 1">已发放</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="updateTime" label="发放日期"></el-table-column>
      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button type="text" v-show="scope.row.type == 0" @click="equitySend(scope.row)">权益发放</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      Infoid: "",
      dialogVisible: false,
      search: "",
      total: 0,
      val: 1, //当前多少页
      currentPage4: 1,
      List: []
    };
  },
  created() {
    this.Infoid = this.$route.query.id;
    this.getList();
  },
  methods: {
    //权益发放
    equitySend(row) {
      this.$confirm(
        "是否对对权益人：" + row.userNikeName + " , 进行权益发放?",
        "权益发放",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        }
      )
        .then(() => {
          let url = "/bonusInfo/grant/" + row.id;
          this.httpGet(url, res => {
            if (res.code === 200) {
              this.$message({
                type: "success",
                message: "权益发放成功!"
              });
              this.getList();
            }else{
              this.$message({
                type: "warning",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    //获取列表
    getList() {
      let url = "/bonusInfo/infoList";
      let params = {
        key:this.search,
        bonusId: this.Infoid,
        pageNum: this.val,
        pageSize: 10
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.List.forEach((element, i) => {
            this.List[i].index = (this.val - 1) * 10 + i + 1;
          });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.head {
  height: 60px;
  .search {
    width: 300px;
    height: 60px;
    float: right;
  }
}
</style>

<style lang="scss">
.equityInfo-Container {
  .el-button + .el-button {
    margin-left: 0px !important;
  }
}
</style>